package com.dyp.modulith_demo.model2d.api.service;

import com.dyp.modulith_demo.model2d.api.model.SampleInfoEventDTO;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

/**
 * 这个具体实现可以随着module1与module2的拆分成多个服务后，改成MQ的实现的生产者。
 */
@Service("ServiceAAsyncImpl2")
public class ServiceAAsyncImpl implements ServiceAApi {
    private final ApplicationEventPublisher eventPublisher;

//    从 Spring 4.3 开始，如果类只有一个构造函数，@Autowired 注解可以省略。
    public ServiceAAsyncImpl(ApplicationEventPublisher eventPublisher)
    {
        this.eventPublisher = eventPublisher;
    }

    @Override
    public void functionA(String info){
        this.eventPublisher.publishEvent(new SampleInfoEventDTO("sample info 2"));
    }
}
